//
//  DiscoverViewController.m
//  FM
//
//  Created by 王方伟 on 2017/12/4.
//  Copyright © 2017年 wfw. All rights reserved.
//

#import "DiscoverViewController.h"
#import "SegmentBarViewController.h"
#import "RecommendViewController.h"
#import "DiscoverService.h"
#import "TabModel.h"

@interface DiscoverViewController ()
@property (weak, nonatomic) SegmentBarViewController *segmentBarVC;
@end

@implementation DiscoverViewController

- (SegmentBarViewController *)segmentBarVC{
    if (_segmentBarVC == nil) {
        SegmentBarViewController *segmentBarVC = [[SegmentBarViewController alloc] init];
        [self addChildViewController:segmentBarVC];
        _segmentBarVC = segmentBarVC;
    }
    return _segmentBarVC;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"发现";
    
    self.segmentBarVC.view.frame = self.view.bounds;
    [self.view addSubview:self.segmentBarVC.view];
    
    
    [DiscoverService getDistcoverTitleWith:[DiscoverRequest request] success:^(DiscoverResponse *response) {
        NSMutableArray *dataArray = [NSMutableArray array];
        for (TabModel *model in response.tabs.list) {
            [dataArray addObject:model.title];
        }
        NSArray *items = [dataArray copy];
        
        // 添加几个自控制器
        // 在contentView, 展示子控制器的视图内容
        
        RecommendViewController *vc1 = [RecommendViewController new];
        
        UIViewController *vc2 = [UIViewController new];
        vc2.view.backgroundColor = [UIColor greenColor];
        
        UIViewController *vc3 = [UIViewController new];
        vc3.view.backgroundColor = [UIColor yellowColor];
        [self.segmentBarVC setUpWithItems:items childVCs:@[vc1, vc2, vc3]];
        [self.segmentBarVC.segmentBar updateWithConfig:^(SegmentBarConfig *config) {
            config.indicatorHeight = 2;
            config.segmentBarBackColor = [UIColor yellowColor];
        }];
    } failure:nil];
    
    
}


@end
